<?php
header("Access-Control-Allow-Origin:*");
/*
  版本1
  学生点击点名接口
  接口方式:http post
  接口:setPoint.php
  传入数据:{"userId":"23","userName":"123","pointed":"1"}

  版本2 更新
  接口方式:http post
  接口:setPoint.php
  传入数据:{"userId":"23","userName":"123","pointed":"1","pointTime":"1234566723"}
  测试地址:http://192.168.16.115/openapi/om_html5/setPoint.php?userId=23&userName=张三&pointed=1&pointTime=1234566723
 */
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
@error_reporting(0);
@set_time_limit(0);
@set_magic_quotes_runtime(0);
@ini_set('memory_limit', '512M');
$whiteboard_config_array = array();
//ini_set("display_errors","On");
//error_reporting(E_ALL);
//DEBUG 接收点名数据
$userId = isset($_REQUEST['userId']) ? $_REQUEST['userId'] : '';
$userName = isset($_REQUEST['userName']) ? $_REQUEST['userName'] : '';
$pointed = isset($_REQUEST['pointed']) ? $_REQUEST['pointed'] : '';
$pointTime = isset($_REQUEST['pointTime']) ? $_REQUEST['pointTime'] : '';
$roomId = isset($_REQUEST['roomId']) ? $_REQUEST['roomId'] : '';
$sn_group_id = isset($_REQUEST['sn_group_id']) ? $_REQUEST['sn_group_id'] : '';
if ($userId && $userName && $pointed && $pointTime) {
    //DEBUG 解析白板配置文件
    $isp = isset($_REQUEST['isp']) && !empty($_REQUEST['isp']) ? $_REQUEST['isp'] : ''; //运营商编号 1 电信 2 移动 3 联通
    if (empty($isp)) {
        $isp = 1;
    }
    $whiteboard_config_array = parse_ini_file("../../config/room/config_whiteboard_".$isp.".ini", false);
    require '../../source/class/memory/memory_driver_redis_multi.php';
    $config_redis = array();
    $config_redis['master'] = array(
        array('host' => $whiteboard_config_array['MEMORY_REDIS_MASTER_SERVER'],
            'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
            'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
            'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
            'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
            'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
        )
    );
    $config_redis['slave'] = array(
        array('host' => $whiteboard_config_array['MEMORY_REDIS_SLAVE_SERVER'],
            'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
            'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
            'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
            'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
            'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
        )
    );
    @file_put_contents('./logs/point/' . $pointTime . '.log', $userId . '_' . $userName . '_' . $pointed . '_' . date('Y-m-d H:i:s', time()) . PHP_EOL, FILE_APPEND);
    //DEBUG 初始化redis
    $redis = RedisClient::getInstance($config_redis);
    $point_num = $redis->incr('point_num_' . $pointTime);
    echo 'ok';
    $redis->close();
}
?>